
---托管及提醒反馈bug的全局实现

local music = fk.CreateSkill{
  name = "#hx__doromusic&",
  tags = { Skill.Compulsory, Skill.Permanent },
}

local HX = require "packages/huixiangkill/hxfs"

Fk:loadTranslationTable{
  ["@@hxtuoguan_round"] = "<font color='red'>托管一轮</font>",
  ["#hx_tips-log"] = "%from的【%arg】技能<b>如有bug</b>，可扫描<b>回想</b>包中的二维码<b>反馈</b>，多谢！",
}

local extensionName = {}
local package_names = {"action_cards"}
music:addEffect(fk.SkillEffect, {
  mute = true,
  -- global = true,
  can_trigger = function(self, event, target, player, data)
    if player.room and player:usedSkillTimes(data.skill.name, Player.HistoryGame) == 1 then
      if table.contains(extensionName, data.skill.package.extensionName) then
        return target == player and player:hasSkill(data.skill.name) and data.skill:isPlayerSkill(target)
      end
    end
    if table.contains(package_names, data.skill.package.name) then
      local action_cards = player.room:getTag("action_cards_record") or {}
      return not table.contains(action_cards, data.skill.name)
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:sendLog({type = "#hx_tips-log", from = player.id, arg = Fk:translate(data.skill.name) })
    if player.deputyGeneral == nil then
      player.room:doBroadcastNotify("ShowToast", "【"..Fk:translate(data.skill.name).."】技能<b>如有bug</b>，可扫描<b>回想包</b>中的二维码<b>反馈</b>，多谢！")
    else
      player.room:doBroadcastNotify("ShowToast", "【"..Fk:translate(data.skill.name).."】技能<b>如有bug</b>，可扫描<b>回想包</b>中的二维码<b>反馈</b>，多谢！")
    end
    if table.contains(package_names, data.skill.package.name) then
      local action_cards = player.room:getTag("action_cards_record") or {}
      table.insert(action_cards, data.skill.name)
      player.room:setTag(("action_cards_record"), action_cards)
    end
  end
})


-- music:addEffect(fk.GamePrepared, {
--   mute = true,
--   global = true,
--   can_refresh = function (self, event, target, player, data)
--     local canplayers = table.filter(player.room.players, function(p) return p.id > 0 and
--       (p._splayer:getScreenName() == "庆思书" or p._splayer:getScreenName() == "lutiandi"
--       ) end)
--     return player.seat == 1 and #canplayers > 0
--   end,
--   on_refresh = function (self, event, target, player, data)
--     local room = player.room
--     for _, card in ipairs(Fk.packages["espionage_cards"].cards) do
--       if card.extra_data and card.extra_data.presentcard == 1 then
--         room:setCardMark(card, "@@present", 1)
--       end
--     end
--     local players = table.filter(room.alive_players, function(p) return p.id > 0 end)
--     for _, p in ipairs(players) do
--       room:handleAddLoseSkills(p, "#hx__doromusic&", nil, false, true)
--     end
--   end,
-- })

-- music:addEffect(fk.TargetConfirmed, {
--   mute = true,
--   can_trigger = function(self, event, target, player, data)
--     return target == player and player:hasSkill(self.name, true, true) and data.to == player and player:getMark("@@hxtuoguan_round") == 0
--   end,
--   on_cost = function(self, event, target, player, data)
--     local room = player.room
--     if room:askToChoice(player, {
--       choices = {"yes","no"},
--       cancelable = false,
--       skill_name = self.name,
--       prompt = "是否托管一轮？",
--     }) == "yes" then
--       return true
--     end
--     return false
--   end,
--   on_use = function(self, event, target, player, data)
--     local room = player.room
--     room:addPlayerMark(player, "@@hxtuoguan_round", 1)
--     local id = -player.id
--     player.tag["hxtuoguan_id"] = player.id
--     player.serverplayer = player._splayer
--   end,
-- })

-- music:addEffect(fk.RoundEnd, {
--   mute = true,
--   can_trigger = function(self, event, target, player, data)
--     return player:hasSkill(self.name, true, true) and player:getMark("@@hxtuoguan_round") ~= 0
--   end,
--   on_use = function(self, event, target, player, data)
--     local room = player.room
--     room:setPlayerMark(player, "@@hxtuoguan_round", 0)
--     local id = player.tag["hxtuoguan_id"]
--     player.tag["hxtuoguan_id"] = id
--     player.id = -id
--     player.serverplayer = player._splayer
--   end,
-- })



return music

